﻿@{
    ViewBag.Title = "BatchSet";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <style>
        .setDiv{
            width:100%;
            height:100%;
        }
    </style>
}

<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="saveas" plain="true">保存</a>
                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>
</div>

<div style="width:200px;float:left;height:100%;">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"
            borderStyle="border:1;" url="" showPager="false"
            allowCellSelect="true" allowCellEdit="false" showColumnsMenu="true" fitColumns="false"
            sortMode="client" onselectionchanged="SelectionChanged">
        <div property="columns">
            <div type="checkcolumn"></div>
            <div field="text" name="text" width="170" headeralign="center" allowsort="true">设置项目</div>
        </div>
    </div>
</div>
<div style="width:400px;float:left;">
    <div class="setDiv fit">
        <div id="BA1" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">赊账额度：</td>
                    <td width="200px" height="32px">
                        <input name="FSheAmount" id="FSheAmount" class="mini-spinner" minValue="-99999999" maxValue="99999999" 
                        showbutton="false" style="width:200px;" align="right"  value="0" TabIndex="15" allowNull="true"/>
                        <div id="ckShe" name="ckShe" class="mini-checkbox" style="margin-right: 20px" readOnly="false" 
                            checked="true" text="可赊账" onvaluechanged="CheckShe"></div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA2" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">会员性别：</td>
                    <td width="200px" height="32px">
                        <input id="FSex" name="FSex" class="mini-combobox" style="width:115px;" showNullItem="false" 
                            allowInput="false" align="left" value ="0" data ="comSex" /> 
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA3" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">会员分类：</td>
                    <td width="200px" height="32px">
                        @Html.Partial("~/Views/Modular/LookupMembersClass.cshtml") 
                    </td>
                </tr>
            </table>
        </div>
        <div id="BA4" class="setDiv">
            <table style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height="32px" align="right">会员折扣：</td>
                    <td width="200px" height="32px">
                        <input name="FDiscount" id="FDiscount" class="mini-spinner" minValue="0" maxValue="1" 
                        showbutton="false" style="width:200px;" align="right"  value="0" TabIndex="15" allowNull="true"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<script>
    var comSex = [
    { "id": "0", "text": "男" },
    { "id": "1", "text": "女" }
    ];

    mini.parse();
    var grid = mini.get("datagrid1");
    var Data;

    function FormShown() {
        var data = [
            { id: 1, text: '会员赊账' }, { id: 2, text: '性别' }, { id: 3, text: '会员分类' }, { id: 4, text: '会员折扣' }
        ];
        grid.setData(data);
        grid.setSelected(data[0]);
    }

    function SetInfoData(data) {
        Data = data;
    }

    function SelectionChanged() {
        $(".fit div").hide();
        var row = grid.getSelected();
        $("#BA" + row.id).show();
    }
    
    function saveas() {
        var row = grid.getSelected();
        switch (row.id) {
            case 1: save1();
                break;
            case 2: save2();
                break;
            case 3: save3();
                break;
            case 4: save4();
                break;
        }
    }

    function save1() {        
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FSheAmount").getValue() + '",'
        json += '"checked":"' + mini.get("ckShe").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save2() {
        debugger;
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FSex").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }

    function save3() {
        debugger;
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FMembersClassID").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function save4() {
        debugger;
        var row = grid.getSelected();
        var json = '[{"rows":"' + Data + '","project":' + row.id + ',';
        json += '"value":"' + mini.getbyName("FDiscount").getValue() + '",'
        json += '"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        Save(json);
    }
    function Save(json) {
        $.post('../Member/SaveBatch', { mjson: json }, function(data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function() {
                    mini.alert("保存完成");
                });
            } else {
                mini.alert("保存失败，" + ret.error);
            }
        });
    }

    function CheckShe() {
        if (!mini.getbyName("ckShe").checked) {
            mini.getbyName("FSheAmount").setValue(0);
            mini.getbyName("FSheAmount").setEnabled(false);
        }
        else {
            mini.getbyName("FSheAmount").setEnabled(true);
        }
    }
</script>
